﻿using Microsoft.Extensions.Options;
using RabbitMQ.Client;
using System;
using System.Collections.Generic;
using System.Data.Common;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ClassLibrary1
{
    public interface IRabbitMqConnectionFactory
    {
        IConnection Connection { get; }
    }

    public class RabbitMqConnectionFactory : IRabbitMqConnectionFactory
    {
        public IConnection Connection { get; }
        public RabbitMqConnectionFactory(IOptions<RabbitMqConnectionOption> option)
        {
            ConnectionFactory connectionFactory = new ConnectionFactory()
            {
                HostName = option.Value.HostName,
                UserName = option.Value.UserName,
                Password = option.Value.Password
            };
            Connection = connectionFactory.CreateConnection();
        }
    }

    public class RabbitMqConnectionOption
    {
        public string HostName { get; set; }

        public string UserName { get; set; }

        public string Password { get; set; }
    }
}
